home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-03-19 | 5.5 KB | 90 lines | [TEXT/MMCC] |
- //------------------------------------------------------------------------------
- // File: gworld.cp
- // Date: 8/23/94
- // Author: Bretton Wade
- //
- // Description: this file contains the methods of the gworld widget class.
- //
- //------------------------------------------------------------------------------
-
- #include "gworld.h"
-
- //------------------------------------------------------------------------------
- // constructor
- //------------------------------------------------------------------------------
- gworld::gworld (window *w) : widget () // constructor
- { // begin
- Rect junk = {0, 0, 10, 10}; // any normal, valid rectangle to start out
- NewGWorld (&world, 0, &junk, 0, 0, 0); // create the gworld
- owner = w->Port (); // get the port that we will be copying this to
- } // end
-
- //------------------------------------------------------------------------------
- // destructor
- //------------------------------------------------------------------------------
- gworld::~gworld (void) // destructor
- { // begin
- DisposeGWorld (world); // finished with the gworld
- } // end
-
- //------------------------------------------------------------------------------
- // Set the cursor to what is appropriate for the gworld
- //------------------------------------------------------------------------------
- void gworld::SetCursor (void) // method to set the cursor to the correct shape
- { // begin
- ::SetCursor (*(GetCursor (crossCursor))); // set the cursor to a plus
- } // end
-
- //------------------------------------------------------------------------------
- // resize the gworld and all the children accordingly
- //------------------------------------------------------------------------------
- void gworld::Resize (EventRecord &event) // method to recompute sizing information from parent
- { // begin
- Rect rect = (*(parent->region))->rgnBBox; // temporary to simplify code
- InsetRect (&rect, 1, 1); // inset the rect just a bit, to make room for the frame
- RectRgn (region, &rect); // adjust the widget region
- rect.right -= rect.left; rect.bottom -= rect.top; // subtractions to make the rectangle zero based
- rect.left = 0; rect.top = 0; // set the zero values
- UpdateGWorld (&world, 0, &rect, 0, 0, 0); // update the gworld buffers
- pixmap = GetGWorldPixMap (world); // get a fresh copy of the pixel map handle, since memory may have moved
- widget::Resize (event); // default behavior
- } // end
-
- //------------------------------------------------------------------------------
- // draw the gworld
- //------------------------------------------------------------------------------
- void gworld::StartDrawing (gw_erase e) // lock down the gworld and set the port appropriately
- { // begin
- LockPixels (pixmap); // make sure memory won't move
- GetGWorld (&curport, &curworld); // store the current drawing environment parameters
- SetGWorld ((CGrafPtr) world, 0); // make the gworld buffer the current drawing environment
- if (e) // if the user wants a clean page
- EraseRect (&world->portRect); // erase the buffer
- } // end
-
- //------------------------------------------------------------------------------
- // draw the gworld
- //------------------------------------------------------------------------------
- void gworld::StopDrawing (gw_update u) // unlock the gworld and reset the port
- { // begin
- SetGWorld (curport, curworld); // restore the original drawing environment
- if (u) // if the user wants to see the results immediately
- CopyBits ((BitMap *) *pixmap, &owner->portBits, &world->portRect, &(*region)->rgnBBox, srcCopy, 0);
- UnlockPixels (pixmap); // let the memory move again
- } // end
-
- //------------------------------------------------------------------------------
- // draw the gworld
- //------------------------------------------------------------------------------
- void gworld::Draw (void) // method to draw the gworld
- { // begin
- LockPixels (pixmap); // make sure that memory doesn't move
- CopyBits ((BitMap *) *pixmap, &owner->portBits, &world->portRect, &(*region)->rgnBBox, srcCopy, 0);
- UnlockPixels (pixmap); // memory can move now
- Rect rect = (*region)->rgnBBox; // copy the bounding rect
- InsetRect (&rect, -1, -1); // expand it by one pixel
- FrameRect (&rect); // frame it
- } // end
-
- //------------------------------------------------------------------------------
-